/**
 * 
 */
package xiaojian.toolkit.ebus.runnable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import xiaojian.toolkit.ebus.EventBus;



/**
 * @author hp
 *
 */
public class TaskOverflowChecker implements Runnable {

    private static final Logger logger = 
    	LoggerFactory.getLogger(TaskOverflowChecker.class);
    
	private	EventBus	eventBus;
	private	int			taskLimit = 1000;
	private	long		timeout = 1000;	//	in ms
	
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		if ( logger.isDebugEnabled() ) {
			logger.debug("endter check overflow");
		}
//		ExecutorService exec = eventBus.getExecutorInCurrentThread();
//		
//		boolean	enabled = eventBus.contains(exec);
//		int		taskCount = ((ThreadPoolExecutor )exec).getQueue().size();
//		if ( exec instanceof ThreadPoolExecutor ) {
//			if ( logger.isDebugEnabled() ) {
//				logger.debug("endter check overflow, step 2, [" + taskCount + "], and enabled:" + enabled);
//			}
//			
//			if ( enabled && (taskCount > taskLimit) ) {
//				eventBus.remove(exec);
//				if ( logger.isWarnEnabled() ) {
//					logger.warn("too manay task [" + taskCount + "], now disable this actor");
//				}
//			}
//			if ( !enabled && (taskCount < taskLimit / 3) ) {
//				eventBus.add(exec);
//				if ( logger.isWarnEnabled() ) {
//					logger.warn("task [" + taskCount + "] down, now enable this actor");
//				}
//			}
//		}
	}

	public EventBus getEventBus() {
		return eventBus;
	}

	public void setEventBus(EventBus eventBus) {
		this.eventBus = eventBus;
	}

	public int getTaskLimit() {
		return taskLimit;
	}

	public void setTaskLimit(int taskLimit) {
		this.taskLimit = taskLimit;
	}

	public long getTimeout() {
		return timeout;
	}

	public void setTimeout(long timeout) {
		this.timeout = timeout;
	}

}
